package com.company.huisuo.biz.dialog

import android.app.Activity
import android.view.LayoutInflater
import com.company.huisuo.base.BaseBlurDialog
import com.company.huisuo.databinding.DialogCartSpecsBinding


class CartSpecsDialog(activity: Activity) : BaseBlurDialog<DialogCartSpecsBinding>(activity) {

    override fun getViewBinding(): DialogCartSpecsBinding {
        return DialogCartSpecsBinding.inflate(LayoutInflater.from(context))
    }

    override fun initView() {
        mBinding.tvOk.setOnClickListener {
            dismiss()
        }

        mBinding.tvSpecs1.setOnClickListener {
            chooseSpecs(1)
        }
        mBinding.tvSpecs2.setOnClickListener {
            chooseSpecs(2)
        }
        mBinding.tvSpecs3.setOnClickListener {
            chooseSpecs(3)
        }
        mBinding.tvSpecs4.setOnClickListener {
            chooseSpecs(4)
        }

        mBinding.tvTemp1.setOnClickListener {
            chooseTemp(1)
        }
        mBinding.tvTemp2.setOnClickListener {
            chooseTemp(2)
        }
        mBinding.tvTemp3.setOnClickListener {
            chooseTemp(3)
        }
        mBinding.tvTemp4.setOnClickListener {
            chooseTemp(4)
        }
        mBinding.tvTemp5.setOnClickListener {
            chooseTemp(5)
        }
    }

    private fun chooseSpecs(position: Int) {
        mBinding.apply {
            tvSpecs1.isSelected = position == 1
            tvSpecs2.isSelected = position == 2
            tvSpecs3.isSelected = position == 3
            tvSpecs4.isSelected = position == 4
        }
    }

    private fun chooseTemp(position: Int) {
        mBinding.apply {
            tvTemp1.isSelected = position == 1
            tvTemp2.isSelected = position == 2
            tvTemp3.isSelected = position == 3
            tvTemp4.isSelected = position == 4
            tvTemp5.isSelected = position == 5
        }
    }
}